package dujiu.leetcode.greed;

import java.util.Arrays;

public class P3074 {
    public int minimumBoxes(int[] apple, int[] capacity) {
        int sum = 0;
        int totalCapacity = 0;
        int boxCount = 0;
        for (int i = 0; i < apple.length; i++) {
            sum += apple[i];
        }
        if (sum == 0){
            return 0;
        }
        Arrays.sort(capacity);
        for (int i = capacity.length-1; i >= 0; i--) {
            if (totalCapacity >= sum){
                return boxCount;
            }
            totalCapacity += capacity[i];
            boxCount++;
        }
        return boxCount;
    }

    public static void main(String[] args) {
        int[] capacity = {2,4,2,7};
        int[] apple = {5,5,5};
        P3074 p = new P3074();
        System.out.println(p.minimumBoxes(apple, capacity));
    }
}
